Skip to content

fix: Make setSessionId synchronous to prevent race with MPRoktLayout#734

Closed
nickolas-dimitrakas wants to merge 1 commit intoworkstation/8.x-Maintenancefrom
fix/synchronous-set-session-id
Closed

fix: Make setSessionId synchronous to prevent race with MPRoktLayout#734
nickolas-dimitrakas wants to merge 1 commit intoworkstation/8.x-Maintenancefrom
fix/synchronous-set-session-id

Conversation

@nickolas-dimitrakas
Copy link
Copy Markdown
Contributor

@nickolas-dimitrakas nickolas-dimitrakas commented Apr 9, 2026

Summary

  • Fixes a race condition where setSessionId was delivered asynchronously (two dispatch_async(main) hops via forwardSDKCall) while MPRoktLayout reads the session synchronously from UserDefaults, causing the session ID to be missing on the execute request.
  • Uses the same direct kit access pattern that getSessionId already uses, matching Android's synchronous behavior.
  • Falls back to forwardSDKCall when kits haven't initialized yet.

Test plan

  • New test: testSetSessionIdIsReceivedByKitSynchronously -- confirms the kit receives the session ID synchronously
  • New test: testSetSessionIdSynchronousDoesNotUseForwardSDKCall -- confirms forwardSDKCall is bypassed when kit is active
  • New test: testSetSessionIdFallsBackToForwardSDKCallWhenKitNotAvailable -- confirms fallback queuing behavior
  • Full test suite passes (33/33 MPRoktTests, full suite green)
  • trunk check clean
  • iOS build succeeds

Made with Cursor

setSessionId was using two async main queue hops (via forwardSDKCall)
before reaching the Rokt SDK, causing a race condition when followed
immediately by MPRoktLayout which reads the session synchronously.

Use the same direct kit access pattern as getSessionId, falling back
to forwardSDKCall only when kits haven't initialized yet.

Made-with: Cursor
@nickolas-dimitrakas nickolas-dimitrakas requested a review from a team as a code owner April 9, 2026 15:45
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 9, 2026

PR Summary

Medium Risk
Changes runtime behavior of MPRokt setSessionId: to bypass the queued forwardSDKCall path when the Rokt kit is active, which could affect call ordering/timing and relies on dynamic selector invocation; fallback queuing remains for uninitialized kits.

Overview
Fixes a race where MPRokt setSessionId: could be delivered too late by attempting to forward the session ID directly and synchronously to the active Rokt kit instance (via activeKitsRegistry), instead of always queueing through forwardSDKCall.

If the Rokt kit isn’t available yet, setSessionId: now falls back to the existing deferred forwardSDKCall path. Unit tests are updated to assert (1) direct synchronous delivery, (2) no forwardSDKCall usage when the kit is present, and (3) correct fallback behavior when it isn’t.

Reviewed by Cursor Bugbot for commit c480e95. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

📦 SDK Size Impact Report

Measures how much the SDK adds to an app's size (with-SDK minus without-SDK).

Metric Target Branch This PR Change
App Bundle Impact 1.82 MB 1.82 MB +N/A
Executable Impact 896 bytes 896 bytes +N/A
XCFramework Size 9.51 MB 9.50 MB -4 KB

➡️ SDK size impact change is minimal.

Raw measurements

Target branch (workstation/8.x-Maintenance):

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1948,"with_sdk_executable_size_bytes":76360,"sdk_impact_kb":1864,"sdk_executable_impact_bytes":896,"xcframework_size_kb":9736}

This PR:

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1948,"with_sdk_executable_size_bytes":76360,"sdk_impact_kb":1864,"sdk_executable_impact_bytes":896,"xcframework_size_kb":9732}

@nickolas-dimitrakas nickolas-dimitrakas deleted the fix/synchronous-set-session-id branch April 9, 2026 15:54
@nickolas-dimitrakas nickolas-dimitrakas restored the fix/synchronous-set-session-id branch April 9, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant